/**
 * @param {string} s
 * @return {string}
 */
export var reverseWords = function (s) {
  return s
    .split(' ')
    .map(word => word.split('').reverse().join(''))
    .join(' ')
}

/**
 * @param {string} s
 * @return {string}
 */
export var reverseWords2 = function (s) {
  let word = ''
  let result = ''
  for (let i = 0; i < s.length; i++) {
    if (s[i] === ' ') {
      result += (result ? ' ' : '') + word
      word = ''
    } else {
      word = s[i] + word
    }
  }
  return result ? result + (word ? ' ' + word : '') : word
}
